
                          Title : Implement word count program using LEX.
____________________________________________________________________________________________________________

CODE:

%{                            
int WordCount=0;
int LineCount=0;    
int CharCount=0;
int SpaceCount=0; 
%}

%%

[a-z,A-Z]     {printf("%d Char  :%s \n",++CharCount,yytext);} 
[a-z,A-Z]*    {printf("%d Word  :%s \n",++WordCount,yytext);}
[" "]         {printf("%d Space \n",++SpaceCount);}
[\n]          {printf("%d Line  \n\n",++LineCount);}             
.             {;}                           

%%


main()
{

yylex();

 printf("Word Count=%d\n",WordCount);
 printf("Line Count=%d\n",LineCount);
 printf("Character Count=%d\n",CharCount);
 printf("Space Count=%d\n",SpaceCount);

}

INPUT:

I am computer engineering student


OUTPUT:

dell@dell-Inspiron-3542:~$ cd Desktop
dell@dell-Inspiron-3542:~/Desktop$ lex WordCount.l
dell@dell-Inspiron-3542:~/Desktop$ cc lex.yy.c -ll
dell@dell-Inspiron-3542:~/Desktop$ ./a.out
I am computer engineering student
1 Char  :I 
1 Space 
1 Word  :am 
2 Space 
2 Word  :computer 
3 Space 
3 Word  :engineering 
4 Space 
4 Word  :student 
1 Line  



























